package edu.sctu.lab03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class UserListServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        //中文乱码问题
        response.setHeader("content-type","text/html;charset=UTF-8");


         //ctrl+x删除super
        // shift+enter换行
        PrintWriter out=response.getWriter();

   // out.write("<table>");
//        out.write("<tr>");
//        out.write("<td>编号</td>");
//        out.write("<td>用户名</td>");
//        out.write("<td>密码</td>");
//        out.write("<td>操作1</td>");
//        out.write("操作2");
//        out.write("</tr>");
//
//
//        out.write("<tr>");
//        out.write("<td>1606101017</td>");
//        out.write("<td>唐慈莹</td>");
//        out.write("<td>123456</td>");
//        out.write("<td>删除</td>");
//        out.write("<td>更新</td>");
//        out.write("</tr>");



        //将以上全注释掉
        //1、查数据库并且得到userList


        Database database=new Database();
        List<User> userList=database.getUserList();

        //2、request空间中新建一个名为userList的变量
        request.setAttribute("userList",userList);

      //3、跳转到userList.jsp页面
        request.getRequestDispatcher("/userList.jsp").forward(request,response);

        //JSP和Servlet的区别？
        //1、JSP的路径是固定的 而Servlet是可以自己配置的
        //2、JSP更擅长写HTML代码
        //3、Servlet更擅长写JAVA代码




    }
}
